<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>JVM垃圾回收机制深度解析</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .card-hover {
            transition: all 0.3s ease;
            border: 1px solid transparent;
        }
        
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
            border: 1px solid rgba(102, 126, 234, 0.3);
        }
        
        .text-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        
        .section-title {
            position: relative;
            padding-left: 20px;
        }
        
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 24px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 2px;
        }
        
        .feature-icon {
            width: 60px;
            height: 60px;
            display: flex;
            align-items: center;
            justify-content: center;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 16px;
            color: white;
            font-size: 24px;
            margin-bottom: 16px;
        }
        
        .timeline-item {
            position: relative;
            padding-left: 40px;
            margin-bottom: 30px;
        }
        
        .timeline-item::before {
            content: '';
            position: absolute;
            left: 10px;
            top: 8px;
            width: 12px;
            height: 12px;
            background: #667eea;
            border-radius: 50%;
            box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.2);
        }
        
        .timeline-item::after {
            content: '';
            position: absolute;
            left: 15px;
            top: 20px;
            width: 2px;
            height: calc(100% + 10px);
            background: #e5e7eb;
        }
        
        .timeline-item:last-child::after {
            display: none;
        }
        
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
        
        .drop-cap {
            float: left;
            font-size: 4rem;
            line-height: 1;
            font-weight: 700;
            margin-right: 8px;
            margin-top: -8px;
            color: #667eea;
            font-family: 'Noto Serif SC', serif;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20">
        <div class="container mx-auto px-6">
            <div class="max-w-4xl mx-auto text-center">
                <h1 class="text-5xl md:text-6xl font-bold mb-6 leading-tight">
                    JVM垃圾回收机制
                    <span class="block text-3xl md:text-4xl mt-4 font-light opacity-90">深度解析与性能优化</span>
                </h1>
                <p class="text-xl md:text-2xl font-light opacity-90 leading-relaxed">
                    探索Java虚拟机的核心机制，理解GC与应用线程的精妙协调
                </p>
                <div class="mt-10 flex justify-center space-x-8">
                    <div class="text-center">
                        <i class="fas fa-memory text-3xl mb-2"></i>
                        <p class="text-sm opacity-80">内存管理</p>
                    </div>
                    <div class="text-center">
                        <i class="fas fa-sync-alt text-3xl mb-2"></i>
                        <p class="text-sm opacity-80">并发协调</p>
                    </div>
                    <div class="text-center">
                        <i class="fas fa-tachometer-alt text-3xl mb-2"></i>
                        <p class="text-sm opacity-80">性能优化</p>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto px-6 py-12 max-w-6xl">
        <!-- Introduction -->
        <section class="bg-white rounded-2xl shadow-xl p-8 md:p-12 mb-12 card-hover">
            <p class="text-lg leading-relaxed text-gray-700">
                <span class="drop-cap">这</span>一问题涉及到JVM的垃圾回收（GC）机制与应用线程的协调，尤其是在高并发环境下，GC的处理策略对于应用的性能至关重要。在Java虚拟机中，垃圾回收是一个关键的内存管理任务，它负责回收不再使用的对象以释放内存。GC的协调问题主要涉及如何在进行垃圾回收时减少对应用线程的影响，以及如何确保垃圾回收能够高效完成。
            </p>
        </section>

        <!-- GC Types Overview -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 section-title">垃圾回收器类型概览</h2>
            <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                <div class="bg-white rounded-xl shadow-lg p-6 card-hover">
                    <div class="feature-icon">
                        <i class="fas fa-stream"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3">串行GC (Serial GC)</h3>
                    <p class="text-gray-600 mb-4">使用单线程进行垃圾回收，适合小型应用或内存较小的环境。</p>
                    <div class="bg-purple-50 rounded-lg p-4">
                        <p class="text-sm text-purple-700"><i class="fas fa-info-circle mr-2"></i>特点：实现简单，但会导致较长的应用线程暂停</p>
                    </div>
                </div>
                
                <div class="bg-white rounded-xl shadow-lg p-6 card-hover">
                    <div class="feature-icon">
                        <i class="fas fa-layer-group"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3">并行GC (Parallel GC)</h3>
                    <p class="text-gray-600 mb-4">使用多个线程进行垃圾回收，缩短回收时间，适合多核处理器环境。</p>
                    <div class="bg-purple-50 rounded-lg p-4">
                        <p class="text-sm text-purple-700"><i class="fas fa-info-circle mr-2"></i>特点：多线程回收，暂停时间相对较短</p>
                    </div>
                </div>
                
                <div class="bg-white rounded-xl shadow-lg p-6 card-hover">
                    <div class="feature-icon">
                        <i class="fas fa-project-diagram"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3">CMS GC</h3>
                    <p class="text-gray-600 mb-4">并发标记清除，最小化GC对应用的暂停时间，与应用线程并发执行。</p>
                    <div class="bg-purple-50 rounded-lg p-4">
                        <p class="text-sm text-purple-700"><i class="fas fa-info-circle mr-2"></i>特点：减少全停顿时间，但可能产生碎片</p>
                    </div>
                </div>
                
                <div class="bg-white rounded-xl shadow-lg p-6 card-hover">
                    <div class="feature-icon">
                        <i class="fas fa-bullseye"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3">G1 GC</h3>
                    <p class="text-gray-600 mb-4">Garbage-First GC，平衡停顿时间和吞吐量，适合大堆内存环境。</p>
                    <div class="bg-purple-50 rounded-lg p-4">
                        <p class="text-sm text-purple-700"><i class="fas fa-info-circle mr-2"></i>特点：增量式并发回收，可控制停顿时间</p>
                    </div>
                </div>
            </div>
        </section>

        <!-- GC Process Visualization -->
        <section class="bg-white rounded-2xl shadow-xl p-8 md:p-12 mb-12">
            <h2 class="text-3xl font-bold mb-8 section-title">GC工作流程可视化</h2>
            <div class="mermaid">
                graph TD
                    A[应用线程运行] --> B{内存不足?}
                    B -->|是| C[触发GC]
                    B -->|否| A
                    C --> D[初始标记<br/>STW]
                    D --> E[并发标记<br/>与应用并发]
                    E --> F[重新标记<br/>STW]
                    F --> G[并发清除<br/>与应用并发]
                    G --> H[内存整理]
                    H --> A
                    
                    style A fill:#667eea,stroke:#fff,stroke-width:2px,color:#fff
                    style C fill:#764ba2,stroke:#fff,stroke-width:2px,color:#fff
                    style D fill:#f093fb,stroke:#fff,stroke-width:2px,color:#fff
                    style F fill:#f093fb,stroke:#fff,stroke-width:2px,color:#fff
            </div>
        </section>

        <!-- Coordination Mechanisms -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 section-title">协调机制详解</h2>
            <div class="bg-white rounded-2xl shadow-xl p-8 md:p-12">
                <div class="space-y-8">
                    <div class="timeline-item">
                        <h3 class="text-xl font-bold mb-3 text-gradient">写屏障 (Write Barriers)</h3>
                        <p class="text-gray-700 leading-relaxed">
                            在并发GC过程中，为了保持GC的准确性，需要在应用线程和GC线程之间插入写屏障。这些屏障可以记录对象的引用变化，确保GC能够正确地跟踪对象的状态。
                        </p>
                    </div>
                    
                    <div class="timeline-item">
                        <h3 class="text-xl font-bold mb-3 text-gradient">内存屏障 (Memory Barriers)</h3>
                        <p class="text-gray-700 leading-relaxed">
                            这些屏障用于确保在多线程环境下，内存操作的顺序性，以避免数据竞争和不一致性问题。GC使用这些屏障来确保在垃圾回收期间应用线程的操作不会干扰GC的正确性。
                        </p>
                    </div>
                    
                    <div class="timeline-item">
                        <h3 class="text-xl font-bold mb-3 text-gradient">停顿时间控制 (Pause Time Control)</h3>
                        <p class="text-gray-700 leading-relaxed">
                            对于像G1 GC这样的垃圾回收器，它会设置目标停顿时间，并通过自适应调节GC的行为来尝试达到这个目标。停顿时间的控制是通过调整GC的回收策略和执行频率来实现的。
                        </p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Advanced Features -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 section-title">高级优化特性</h2>
            <div class="grid grid-cols-1 md:grid-cols-2 gap-8">
                <div class="bg-gradient-to-br from-purple-50 to-pink-50 rounded-xl p-8 border border-purple-200">
                    <div class="flex items-start">
                        <div class="mr-4">
                            <i class="fas fa-rocket text-3xl text-purple-600"></i>
                        </div>
                        <div>
                            <h3 class="text-xl font-bold mb-3">逃逸分析</h3>
                            <p class="text-gray-700">
                                现代JVM通过逃逸分析技术来优化GC性能。逃逸分析可以识别那些不会逃出方法的对象，